package DAO;

import Connect.ConnectDB;
import java.awt.List;
import javax.swing.*;
import java.sql.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

public class EmpDAO {
    Connection conn;
    ResultSet rsDep = null;
    Statement st;
    PreparedStatement pst;
    
    public EmpDAO(){
         ConnectDB cdb = new ConnectDB();
        cdb.getConnect();
        this.conn = cdb.conn;

        loadDataEmp();
    }
    
     public void loadDataEmp() {
        try {
            String query = "SELECT "
                    + "             * "
                    + "     FROM "
                    + "             Employees";
            st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rsDep = st.executeQuery(query);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public DefaultTableModel loadTableEmp(int DepNo) {
        try {
            String query = "Select * From Employees WHERE DEPTNO=?";
            PreparedStatement ps = conn.prepareStatement(query);
            ps.setInt(1, DepNo);
            rsDep = ps.executeQuery();
            
            Vector nameCol = new Vector();
            nameCol.add("Employee ID");
            nameCol.add("Employee Name");
            nameCol.add("Design ID");
            nameCol.add("Section ID");
            


            DefaultTableModel dtm = new DefaultTableModel(nameCol, 0);

            while (rsDep.next()) {

                Vector dataRow = new Vector();
                dataRow.add(rsDep.getString("EMPID"));
                dataRow.add(rsDep.getString("EMPNAME"));
                dataRow.add(rsDep.getString("DEPTNO"));
                dataRow.add(rsDep.getString("DESIGNID"));
                dtm.addRow(dataRow);
            }
            return dtm;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
}
